<?php

namespace plugin\ycMassage\app\model;

use plugin\ycMassage\utils\enum\WinnerlookState;

class MassageWinnerlookPrivacy extends Model {
    public static function getFindNumber($saas_appid, $channels, $province_id = null, $city_id = null) {

        $where = [
            'saas_appid' => $saas_appid,
            'channels' => $channels,
            'state' => WinnerlookState::YES['value']
        ];
        if ($city_id) {
            $data = self::where($where)->where(['city_id' => $city_id])->find();
            if ($data) {
                return $data;
            }
        } elseif ($province_id) {
            $data = self::where($where)->where(['province_id' => $province_id])->find();
            if ($data) {
                return $data;
            }
        }
        $data = self::where($where)->find();

        if ($data) {
            return $data;
        }
        throw new \Exception('暂无可用号码');
    }
}
